<?php

namespace App\Support\CustomForm;

class ValidateSupport
{

    /**
     * 是否必填
     *
     * @var bool
     */
    protected bool $required = false;

    /**
     * 内容长度最小值
     *
     * @var int
     */
    protected int $min = 0;

    /**
     * 内容长度最大值
     *
     * @var int
     */
    protected int $max = 99999999;


    private function __construct(bool $required)
    {
        $this->required = $required;
    }

    /**
     * @return bool
     */
    public function getRequired(): bool
    {
        return $this->required;
    }

    /**
     * @return int
     */
    public function getMin(): int
    {
        return $this->min;
    }

    /**
     * @return int
     */
    public function getMax(): int
    {
        return $this->max;
    }


    /**
     * @param bool $required
     * @return ValidateSupport
     */
    public static function getInstance(bool $required): ValidateSupport
    {
        return new self($required);
    }

    /**
     * @param int $min
     * @param int $max
     * @return $this
     */
    public function setContentLength(int $min, int $max): ValidateSupport
    {
        return $this->setContentLengthMin($min)->setContentLengthMax($max);
    }

    /**
     * @param int $min
     * @return $this
     */
    public function setContentLengthMin(int $min): ValidateSupport
    {
        $this->min = $min;
        return $this;
    }

    /**
     * @param int $max
     * @return $this
     */
    public function setContentLengthMax(int $max): ValidateSupport
    {
        $this->max = $max;
        return $this;
    }

    /**
     * 返回校验数据字段
     *
     * @return array
     */
    public function build(): array
    {
        return get_object_vars($this);
    }
}
